package com.ruoyi.customer.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.customer.domain.CustomerDeviceBind;
import com.ruoyi.customer.domain.CustomerDeviceBindVO;
import com.ruoyi.customer.service.ICustomerDeviceBindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户设备绑定Controller
 * 
 * @author luogongquan
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/customerDeviceBind")
public class CustomerDeviceBindController extends BaseController
{
    @Autowired
    private ICustomerDeviceBindService customerDeviceBindService;

    /**
     * 查询用户设备绑定列表
     */
    @RequiresPermissions("customer:customerDeviceBind:list")
    @GetMapping("/list")
    public TableDataInfo list(CustomerDeviceBind customerDeviceBind)
    {
        startPage();
        List<CustomerDeviceBind> list = customerDeviceBindService.selectCustomerDeviceBindList(customerDeviceBind);
        return getDataTable(list);
    }
    /**
     * 查询用户设备绑定列表
     */
    @RequiresPermissions("customer:customerDeviceBind:list")
    @GetMapping("/list2")
    public TableDataInfo list2(CustomerDeviceBindVO customerDeviceBind)
    {
        startPage();
        List<CustomerDeviceBindVO> list = customerDeviceBindService.selectCustomerDeviceBindList2(customerDeviceBind);
        return getDataTable(list);
    }

    /**
     * 查询用户设备绑定列表
     */
    @GetMapping("wx/list")
    public AjaxResult wxList(CustomerDeviceBindVO customerDeviceBind)
    {
        customerDeviceBind.setCustomerId(SecurityUtils.getUserId());
        List<CustomerDeviceBindVO> list = customerDeviceBindService.selectCustomerDeviceBindList2(customerDeviceBind);
        return success(list);
    }

    /**
     * 导出用户设备绑定列表
     */
    @RequiresPermissions("customer:customerDeviceBind:export")
    @Log(title = "导出用户设备绑定列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerDeviceBind customerDeviceBind)
    {
        List<CustomerDeviceBind> list = customerDeviceBindService.selectCustomerDeviceBindList(customerDeviceBind);
        ExcelUtil<CustomerDeviceBind> util = new ExcelUtil<CustomerDeviceBind>(CustomerDeviceBind.class);
        util.exportExcel(response, list, "用户设备绑定数据");
    }

    /**
     * 获取用户设备绑定详细信息
     */
    @RequiresPermissions("customer:customerDeviceBind:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(customerDeviceBindService.selectCustomerDeviceBindById(id));
    }

    /**
     * 新增用户设备绑定
     */
    @RequiresPermissions("customer:customerDeviceBind:add")
    @Log(title = "用户设备绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerDeviceBind customerDeviceBind)
    {
        return toAjax(customerDeviceBindService.insertCustomerDeviceBind(customerDeviceBind));
    }

    /**
     * 新增用户设备绑定
     */
    @Log(title = "微信用户设备绑定", businessType = BusinessType.INSERT)
    @GetMapping("wx/add")
    public AjaxResult wxAdd(String deviceNo)
    {
        clearPage();
        return toAjax(customerDeviceBindService.insertCustomerDeviceBind(deviceNo));
    }

    /**
     * 修改用户设备绑定
     */
    @RequiresPermissions("customer:customerDeviceBind:edit")
    @Log(title = "用户设备绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerDeviceBind customerDeviceBind)
    {
        return toAjax(customerDeviceBindService.updateCustomerDeviceBind(customerDeviceBind));
    }

    /**
     * 删除用户设备绑定
     */
    @RequiresPermissions("customer:customerDeviceBind:remove")
    @Log(title = "用户设备绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerDeviceBindService.deleteCustomerDeviceBindByIds(ids));
    }

    /**
     * 删除用户设备绑定
     */
    @Log(title = "用户设备绑定", businessType = BusinessType.DELETE)
	@GetMapping("wx/remove/{ids}")
    public AjaxResult wxRemove(@PathVariable Long[] ids)
    {
        return toAjax(customerDeviceBindService.deleteCustomerDeviceBindByIds(ids));
    }

}
